import React, { useState, useEffect } from 'react'
// 快捷键 rafc

export default () => {
    const [count, setCount] = useState(0)
    const [clock, setClock] = useState(new Date())

    useEffect(() => {
        console.log('~~effct count')
        document.title = count
    }, [count])

    useEffect(() => {
        console.log('~~effct timer')
        const timer = setInterval(() => {
            setClock(new Date())
        }, 1000)
        return () => clearInterval(timer)
    }, [])

    return (
        <div>
            <h3>hooks基础</h3>
            <div>计数：{count}</div>
            <button onClick={() => setCount(count + 1)}>add</button>
            <div>时钟：{clock.toLocaleTimeString()}</div>
        </div>
    )
}
